<?php
	require_once realpath(dirname(__FILE__)) . '/../Configuration.php';

	abstract class AbstractBean {
		
		static private $log = null;
		
		public function __construct(){
			self::$log = Logger::getLogger('AbstractBean');
		}
		
	    public function __call($name, $arguments) {
	        if (strpos($name, 'get') === 0) {
	            $property = strtolower(substr($name,3,1)) . substr($name,4);
	            return $this->$property;
	        }
	        elseif (strpos($name, 'set') === 0) {
	            $property = strtolower(substr($name,3,1)) . substr($name,4);
	            return $this->$property = $arguments[0];
	        }
	        else {
	        	self::$log->error('Method $name does not exist');
	            throw new Exception("Method $name does not exist");
	        }
	    }
	
	    public function __get($name) {
	        $getter = 'get' . ucfirst($name);
	        self::$log->debug("Getter composto: $getter.");
	        if (method_exists($this, $getter)) {
	        	self::$log->debug("Getter $getter in chiamata");
	            return call_user_func(array($this, $getter));
	        }
	        return $this->$name;
	    }
	
	    public function __set($name, $value) {
	        $setter = 'set' . ucfirst($name);
	        self::$log->debug("Setter composto: $setter.");
	        if (method_exists($this, $setter)) {
	            call_user_func(array($this, $setter), $value);
	        }
	        else {
	            $this->$name = $value;
	        }
	    }
	}